package com.pxx.pj.pxx.controller;

import com.pxx.pj.common.pojo.JsonResult;
import com.pxx.pj.pxx.pojo.PxxRole;
import com.pxx.pj.pxx.service.PxxRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PxxRoleController {
    @Autowired
    private PxxRoleService pxxRoleService;

    //删除角色
    @RequestMapping("role/doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        pxxRoleService.deleteObjectsById(id);
        return new JsonResult("delete ok");
    }

    //添加 用户
    @GetMapping("/role/doFindRoles")
    public JsonResult doFindRoles(){
        return new JsonResult(pxxRoleService.findObjects());
    }

    //更新 角色 管理 页面
    @GetMapping("/role/doFindObjectById")
    public JsonResult doFindObjectById(Integer id){
        return new JsonResult(pxxRoleService.findById(id));
    }
    @PostMapping("/role/doUpdateObject")
    public JsonResult doUpdateObject(PxxRole entity, Integer[] menuIds){
        pxxRoleService.updateObject(entity,menuIds);
        return new JsonResult("Update ok");
    }


    //添加 角色管理 页面 数据
    @PostMapping("/role/doSaveObject")
    public JsonResult doSaveObject(PxxRole entity,Integer[] menuIds){
        pxxRoleService.saveObject(entity,menuIds);
        return new JsonResult("save ok");
    }

    //显示 角色管理 页面 数据
    @GetMapping("/role/doFindPageObjects")
    public JsonResult doFindPageObjects(String name,Integer pageCurrent){
        return new JsonResult(pxxRoleService.findPageObjects(name,pageCurrent));
    }
}
